package com.boarsoft.boar.common.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.boarsoft.common.Util;

public class DateStrImpl implements ConstraintValidator<DateStr, String> {
	private String format;

	@Override
	public void initialize(DateStr ds) {
		format = ds.format();
	}

	@Override
	public boolean isValid(String str, ConstraintValidatorContext cvc) {
		return Util.strIsEmpty(str) || (Util.strIsNotEmpty(str) && Util.str2date(str, format) != null);
	}
}